package common

import (
	"encoding/json"
	"log"
)

//通用返回格式

type Resp struct {
	Code int
	Msg  string
	Data map[string]interface{}
}

func Success(data map[string]interface{}, msg string) []byte {
	resp := new(Resp)

	resp.Code = 200
	resp.Msg = msg
	resp.Data = data
	respJson, err := json.Marshal(resp)
	if err != nil {
		log.Panicln(err)
	}
	return respJson
}
func Fail(data map[string]interface{}, msg string) []byte {
	resp := new(Resp)

	resp.Code = 500
	resp.Msg = msg
	resp.Data = data
	respJson, err := json.Marshal(resp)
	if err != nil {
		log.Panicln(err)
	}
	return respJson
}
